﻿/*
 * Drawer.cs
 * 
 * Represents a drawer in the supply room, stores row and column number
 * and a list of items in the drawer.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Supply_Fetch
{
    public class Drawer
    {
        private int row, column;
        private List<Item> items;

        /// <summary>
        /// Return the row value of the drawer
        /// </summary>
        /// <returns>row value</returns>
        public int GetRow()
        {
            return row;
        }

        /// <summary>
        /// Return the column value of the drawer
        /// </summary>
        /// <returns>column value</returns>
        public int GetColumn()
        {
            return column;
        }

        /// <summary>
        /// Return the list of items in the drawer
        /// </summary>
        /// <returns>list of items</returns>
        public List<Item> GetItems()
        {
            return items;
        }

        /// <summary>
        /// Add an item to the drawer's list of items
        /// </summary>
        /// <param name="item">item to be added</param>
        public void AddItem(Item item)
        {
            if (items == null)
                items = new List<Item>();

            items.Add(item);
        }

        /// <summary>
        /// Print out drawer values and item contents, will display an item list if drawer contains any
        /// </summary>
        /// <returns>string description of drawer values and contents</returns>
        public String ToString()
        {
            String desc = "Drawer - Col: " + GetColumn() + " Row: " + GetRow();

            List<Item> items = this.GetItems();

            if (items != null)
            {
                if (items.Count > 0)
                {
                    desc += "\n   Items: ";

                    foreach (Item item in items)
                    {
                        desc += "" + item.ToString() + ", ";
                    }
                }
            }

            desc += "\n";

            return desc;
        }

        /// <summary>
        /// Drawer constructor
        /// </summary>
        /// <param name="row">row value</param>
        /// <param name="column">column value</param>
        public Drawer(int row, int column)
        {
            this.row = row;
            this.column = column;
        }

        /// <summary>
        /// Drawer constructor with item list
        /// </summary>
        /// <param name="row">row value</param>
        /// <param name="column">column value</param>
        /// <param name="items">list of items</param>
        public Drawer(int row, int column, List<Item> items)
        {
            this.row = row;
            this.column = column;
            this.items = items;
        }
    }
}
